<template>
    <el-dialog title="设备选择" v-model="visible" width="800px" top="5vh" append-to-body>
        <el-form :model="queryParams" ref="queryRef" v-show="showSearch" :inline="true" label-width="68px">
         <el-form-item label="设备名称" prop="deviceName">
            <el-input
               v-model="queryParams.deviceName"
               placeholder="请输入设备名称"
               clearable
               style="width: 240px"
            />
         </el-form-item>
        <el-form-item label="资产编码" prop="deviceNo">
            <el-input
               v-model="queryParams.deviceNo"
               placeholder="请输入资产编码"
               clearable
               style="width: 240px"
            />
         </el-form-item>
        <el-form-item label="申请科室" prop="applyDept">
            <el-input
               v-model="queryParams.applyDept"
               placeholder="请输入申请科室"
               clearable
               style="width: 240px"
            />
         </el-form-item>
        <el-form-item>
            <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
            <el-button icon="Refresh" @click="resetQuery">重置</el-button>
         </el-form-item>
      </el-form>

      <!-- 表格数据 -->
      <el-table v-loading="loading" :data="deviceList"  @selection-change="handleSelectionChange">
        <el-table-column type="selection" width="55" />
        <el-table-column label="设备名称" prop="deviceName"  />
         <el-table-column label="资产编码" prop="deviceNo"  />
         <el-table-column label="科室名称" prop="deviceSectionName"  />
         <el-table-column label="购置金额" prop="purchaseMoney"  />
      </el-table>
      <pagination
         v-show="total > 0"
         :total="total"
         v-model:page="queryParams.pageNo"
         v-model:limit="queryParams.pageSize"
         @pagination="getList"
      />
        <template #footer>
            <div class="dialog-footer">
               <el-button type="primary" @click="submitForm">确 定</el-button>
               <el-button @click="cancel">取 消</el-button>
            </div>
         </template>
    </el-dialog>
</template>

<script setup name="deviceChoose">
import {listDevice} from "@/api/system/device"
const router = useRouter()
const { proxy } = getCurrentInstance()
const visible = ref(false)
const showSearch = ref(true)
const loading = ref(false)
const deviceList = ref([])
const total = ref(0)
const tableSections = ref([])

const data = reactive({
  form: {},
  queryParams: {
    pageNo: 1,
    pageSize: 5
  },
  rules: {}
})
const { queryParams, form, rules } = toRefs(data)

/** 查询列表 */
function getList() {
    loading.value = true
    listDevice(queryParams.value).then(response => {
        deviceList.value = response.result.records
        total.value = response.result.total
        loading.value = false
  })
}
function handleQuery(){
  queryParams.value.pageNo = 1
  getList()
}
function resetQuery(){}

function submitForm(){
    proxy.$emit('data-from-child', tableSections.value);
    visible.value = false
}

function cancel(){
      visible.value = false
}
// 显示弹框
function show() {
  visible.value = true
  getList()
}

/** 多选框选中数据 */
function handleSelectionChange(selection) {
    tableSections.value = selection
}

defineExpose({
  show,
})
</script>